const mongoose = require('mongoose')

const { Schema, model } = mongoose

// 通过 schema 设计出表结构，简单结构复杂结构都可以，每一条自动创建 _id
const articleSchema = new Schema({
  title: {
    type: String,
    required: true // 必要
  },
  content: {
    type: String,
    required: true // 必要
  },
  authorId: { // 关联用户表
    type: String,
    required: true
  },
  authorName: {
    type: String,
    required: true
  },
  createdAt: {
    type: Date,
  },
  cover: {
    type: String
  }
})

// User 表
module.exports = model('Article', articleSchema)
